package net.xi.news.controller;


import cn.hutool.core.util.ObjectUtil;
import cn.hutool.db.PageResult;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j;
import net.xi.news.dao.EchartsMapper;
import net.xi.news.pojo.Echarts;
import net.xi.news.vo.EchartsVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.thymeleaf.util.StringUtils;

import java.util.List;

/**
 * @author ZhangYu
 * @Description:
 * @create 2021-03-03 17:59
 **/
@Slf4j
@RequestMapping("/echarts/")
@Controller
public class EchartsController {


    @Autowired
    private EchartsMapper echartsMapper;

    /**
     * 查询数据列表
     * @param echartsVo
     * @return
     */
    @GetMapping("list")
    @ResponseBody
    public List<Echarts> findEchartsByPage(EchartsVo echartsVo){
        LambdaQueryWrapper<Echarts> queryWrapper= Wrappers.lambdaQuery();
        if (ObjectUtil.isNotNull(echartsVo)){
            if (!StringUtils.isEmpty(echartsVo.getName())){
                queryWrapper.like(Echarts::getName,echartsVo.getName());
            }
            if (echartsVo.getType()!=null){
                queryWrapper.eq(Echarts::getType,echartsVo.getType());
            }
        }
        List<Echarts> echartsPage = echartsMapper.selectList(queryWrapper);
        return echartsPage;
    }
}
